{include file="public/header"}
<style type="text/css">
textarea{width:100%;height:90px;font-size: 0.9rem}
textarea::-webkit-input-placeholder {
	color: #fff;
	font-size: 0.9rem
}
textarea:-moz-placeholder {
	color: #fff;
	font-size: 0.9rem
}
.res_section1xx .all_1 .f1{
	border-bottom: none;
}
.res_section1 .all_1 .f1 .s1990{vertical-align:top;}
</style>
<body>
<div class="bg_fixed_v10_1"></div>
	<div class="sectionY sectionY_tttt" >
		<a href="{$back_url}">
			<img src="__PUBLIC__/home/images/v10_a9.png" alt="" class="a1">
		</a>
		<p class="p1">
			<span class="ppp_title">我要投诉</span>
		</p>
	</div>
	<div class="kong1"></div>
<form class='form_binding' enctype="multipart/form-data">
	<div class="res_section1 res_section1xx">
		<div class="all_1">
			<div class="f1">
				<p class="s1 s1990">投诉描述：</p>
				<div class="dkl">
					<textarea style="background: none;border: none;color: #fff" name='content' placeholder="请输入投诉描述，选填" maxlength='10' ></textarea>
				</div>
			</div>
			<div class="f1">
				<span class="s1 ">证明图片：</span>
                <div class="dkl" style="padding: 20px 10px">
					<!-- 如果是安卓地址，那就调用上传，如果不是，直接上传 -->
					<span class="s2 pic_btn" style="border-radius: 5px; background-color: #268bc8;border: 1px solid #29f5ff;color: #fff;padding: 2px;">选择证明截图</span>
					<input type="file" id="file" onchange="imgChange(this);" style="width: 0px;height:0px;">
					<div class="dhh">
						<img id="imghead" class="show_btn" src="" alt="" style="width: 120px; height: 120px;">
					</div>
					<!--<input type="file"  name='files' onchange="imgChange(this)" class="input1" />-->
				</div>
			</div>

			<div class="sub">
				<input type='hidden' name='upload_geturl' id="upload_geturl"  />
				<input type="button" value="确认提交" onclick='return check_repwd();' />
			</div>
		</div>
	</div>
</form>
</body>
<script>
	var is_app=0;
	try {
		is_app = android.getType();
	}catch (e) {
	}
	$(function(){
		$(".pic_btn").click(function(){
			if(is_app==1){
				android.uploadImage(location.origin+"/home/Upload/appupimg.html");
			}else{
				$(this).siblings("input").click();
			}
		});
	})
</script>
<script type="text/javascript">
	//安卓回调
	function setImage(img_url) {
		$("#imghead").attr('src',img_url); // 修改img标签src属性值
		$("#upload_geturl").val(img_url);
	}
    function imgChange(obj) {
		var docObj=$(obj).get(0);
		console.log(obj);
		if (docObj.files && docObj.files[0]) {
			if(!/image\/\w+/.test(docObj.files[0].type)){
				//图片文件的type值为image/png或image/jpg
				layer.msg("文件必须为图片！");
				return false;
			}
			var formData = new FormData();
			formData.append("files",docObj.files[0]);
			$.ajax({
				url: "{:url('Upload/upimg')}",
				type: "POST",
				data: formData,
				/**
				 *必须false才会自动加上正确的Content-Type
				 */
				contentType: false,
				/**
				 * 必须false才会避开jQuery对 formdata 的默认处理
				 * XMLHttpRequest会对 formdata 进行正确的处理
				 */
				processData: false,
				success: function (rs) {
					rs = JSON.parse(rs);
					if(rs.status==0){
						setImage(rs.data)
					}else{
						layer.alert(rs.info,{shade:0.2});return false;
					}
				},
				error: function () {
					layer.msg('系统错误，请稍后重试');
				}
			});
		} else {
			layer.msg('请上传图片');
		}
		return true;
    }
    /*开始检测交易密码和各个选项是否填写  xuanfeng 20190617*/
    function check_repwd(){
        var name= $('textarea[name=content]').val();
        var img_url=$('#upload_geturl').val();
        if(name==''){
            if(img_url==''){
                layer.alert('请填写投诉描述或上传证明图片！');return false;
            }
        }
        $.ajax({
            type: 'POST',
            url: "{:url('User/doappeal')}",
            dataType: "json",
            data: {content:name,upload_geturl:img_url},
            success:function(re){
                var obj=re;
                if(obj.s==1){
                    layer.msg(obj.msg,{shade:0.6,time:1000,end:function(){
                            window.location.href=window.location.href;
                        }});
                }else{
                    layer.alert(obj.msg,{shade:0.2});return false;
                }
            },
            error:function(){
                layer.alert('系统繁忙，请稍后再试！',{shade:0.2});
            }
        });
    }
</script>
</html>
